package org.jeecg.modules.websocket.config;

import lombok.RequiredArgsConstructor;
import org.jeecg.modules.websocket.handler.WebSocketHandler;
import org.jeecg.modules.websocket.interceptor.WebSocketAuthInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * @author by sean
 * @desc:
 * @since 2024-10-16 星期三 08:38:19
 */
@Configuration
@RequiredArgsConstructor
@EnableWebSocket
public class WebSocketConfigurerImpl implements WebSocketConfigurer {

    private final WebSocketAuthInterceptor authInterceptor;

    private final WebSocketHandler httpAuthHandler;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry
                .addHandler(httpAuthHandler, "/ws")
                .addInterceptors(authInterceptor)
                .setAllowedOrigins("*");
    }

}
